/*
 *  txdnet.cn tonydon
 * 
 */
package cn.txdnet.txcms.admin.action;

import cn.txdnet.txcms.query.TinyCmtQuery;
import cn.txdnet.txcms.service.TinyCmtService;
import cn.txdnet.txweb.model.ModelUtil;
import cn.txdnet.txweb.model.ModelView;
import cn.txdnet.txweb.utils.BeanUtil;
import cn.txdnet.txweb.utils.Message;
import cn.txdnet.txweb.utils.WebUtil;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author txdnet
 */
public class TinyCmtAction {

    /**
     * 批量删除
     *
     * @param req
     * @return
     */
    public ModelView delete_batch(HttpServletRequest req) {
        String ids = WebUtil.getArrStr(req, "ids", null);
        if (ids == null) {
            return ModelUtil.getTextModel(Message.MSG_PARAM_ERR);
        }
        int del_num = TinyCmtService.deleteBatch(ids);
        if (del_num > 0) {
            return ModelUtil.getTextModel(del_num);
        } else {
            return ModelUtil.getTextModel(Message.MSG_FAIL);
        }
    }

    /**
     * 更新发布状态
     *
     * @param req
     * @return
     */
    public ModelView update_pubstate(HttpServletRequest req) {
        String ids = WebUtil.getArrStr(req, "ids", null);
        byte pubstate = WebUtil.getByte(req, "pubstate", -1);
        if (ids == null || pubstate < 0) {
            return ModelUtil.getTextModel(Message.MSG_PARAM_ERR);
        }
        int num = TinyCmtService.updatePubstateBatch(ids, pubstate);
        if (num > 0) {
            return ModelUtil.getTextModel(num);
        } else {
            return ModelUtil.getTextModel(Message.MSG_FAIL);
        }
    }

    /**
     * 查询评论
     * @param req
     * @return
     * @throws Exception 
     */
    public ModelView list_factor(HttpServletRequest req) throws Exception {
        TinyCmtQuery query = BeanUtil.parseRequestToBean(TinyCmtQuery.class, req);
        return ModelUtil.getJsonModel(TinyCmtService.queryByFactor(query));
    }
}
